package com.corona.game;

import com.badlogic.gdx.audio.Music;
import com.corona.Game;
import com.corona.game.util.audio.AudioLoader;

/* compiled from: Action.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/FadeMusic.class */
public class FadeMusic extends Action {
    Music music;
    float rate;
    float maxVol;
    public static Action currFadeMusic;
    public boolean insertNextAction;
    public static Music silence;

    public FadeMusic(Music music, float rate, Action nextAction) {
        this(music, rate, 1.0f, nextAction);
    }

    public FadeMusic(Music music, float rate, float maxVol, Action nextAction) {
        this(music, rate, 1.0f, false, nextAction);
    }

    public FadeMusic(Music music, float rate, float maxVol, boolean insertNextAction, Action nextAction) {
        super(new Object[0]);
        this.rate = -0.05f;
        this.maxVol = 1.0f;
        this.insertNextAction = false;
        silence = AudioLoader.loadMusic("music/silence1.ogg");
        silence.setVolume(0.0f);
        silence.setLooping(true);
        this.music = music;
        this.rate = rate;
        this.maxVol = maxVol;
        this.insertNextAction = insertNextAction;
        this.nextAction = nextAction;
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        currFadeMusic = this;
        if (this.music == null) {
            this.music = silence;
        }
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (currFadeMusic == this) {
            float volume = this.music.getVolume() + this.rate;
            if (volume < 0.0f) {
                volume = 0.0f;
            }
            this.music.setVolume(volume);
        }
        if (currFadeMusic != this || this.music.getVolume() <= 0.1f || this.music.getVolume() >= this.maxVol) {
            if (this.music.getVolume() < this.maxVol) {
                this.music.pause();
            }
            this.music.setVolume(this.maxVol);
            game.actionStack.remove(this);
            if (currFadeMusic == this || this.insertNextAction) {
                game.insertAction(this.nextAction);
            }
        }
    }
}
